﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

using AimGameLibrary.GameObject;

namespace AimGameLibrary.GameObject
{

    public class GameRectangle : GameBaseValue
    {
        Rectangle myrectangle;
        public Rectangle MyrectanglE { get { myrectangle = (Rectangle)GetParentValue(); return myrectangle; } set { myrectangle = value; SetParentValue(myrectangle); } }

        public override void LoadData(Identification getdata, int IndexData, NodeData node)
        {
            InputMode = (NodeInputMode)getdata.Items.GetValue(IndexData + 1);

            if (InputMode == NodeInputMode.Rectangle_1)
                Listnameparent.Add(node.Data);
            else if (InputMode == NodeInputMode.Int_4)
            {
                String Temp = node.Data;
                Listnameparent.Add(Script.GetName(Temp, 4, 0));
                Listnameparent.Add(Script.GetName(Temp, 4, 1));
                Listnameparent.Add(Script.GetName(Temp, 4, 2));
                Listnameparent.Add(Script.GetName(Temp, 4, 3));
            }
            else MyrectanglE = (Rectangle)getdata.Items.GetValue(IndexData + 2);
        }

        protected override object GetParentValue()
        {
            if (Listparent.Count > 0)
            {
                if (InputMode == NodeInputMode.Rectangle_1
                    && Listparent[0].GetType() == typeof(GameRectangle))
                {
                        GameRectangle temprectangle = (GameRectangle)Listparent[0];
                        return temprectangle.MyrectanglE;                    
                }
                else if (InputMode == NodeInputMode.Int_4
                    && Listparent.Count == 4)
                {
                    if (Listparent[0].GetType() == typeof(GameInt) && Listparent[1].GetType() == typeof(GameInt) && Listparent[2].GetType() == typeof(GameInt) && Listparent[3].GetType() == typeof(GameInt))
                    {
                        GameInt tempintX = (GameInt)Listparent[0];
                        GameInt tempintY = (GameInt)Listparent[1];
                        GameInt tempintWidht = (GameInt)Listparent[2];
                        GameInt tempintHigth = (GameInt)Listparent[3];
                        return new Rectangle(tempintX.MyinT, tempintY.MyinT, tempintWidht.MyinT, tempintHigth.MyinT);
                    }
                    else return myrectangle;
                }
                else return myrectangle;
            }
            else return myrectangle;
        }

        protected override void SetParentValue(object obj)
        {
            if (Listparent.Count > 0)
            {
                if (InputMode == NodeInputMode.Rectangle_1)
                {
                    if (Listparent[0].GetType() == typeof(GameRectangle))
                    {
                        GameRectangle temprectangle = (GameRectangle)Listparent[0];
                        temprectangle.MyrectanglE = (Rectangle)obj;
                    }
                }
                else if (InputMode == NodeInputMode.Int_4)
                {
                    if(Listparent.Count == 4)
                        if (Listparent[0].GetType() == typeof(GameInt) && Listparent[1].GetType() == typeof(GameInt) && Listparent[2].GetType() == typeof(GameInt) && Listparent[3].GetType() == typeof(GameInt))
                        {
                            GameInt tempintX = (GameInt)Listparent[0];
                            GameInt tempintY = (GameInt)Listparent[1];
                            GameInt tempintWidht = (GameInt)Listparent[2];
                            GameInt tempintHigth = (GameInt)Listparent[3];
                            Rectangle temprectangle = (Rectangle)obj;
                            tempintX.MyinT = temprectangle.X;
                            tempintY.MyinT = temprectangle.Y;
                            tempintWidht.MyinT = temprectangle.Width;
                            tempintHigth.MyinT = temprectangle.Height;
                        }
                }
            }
        }
    }
}
